<template>
  <el-table :data="tableData">
    <el-table-column label="时间" type="index" width="180" align="center">
      <template #default="{ row }">
        <el-date-picker
          v-model="row.recordTime"
          type="date"
          placeholder="请选择时间"
          value-format="YYYY-MM-DD HH:mm:ss"
          :disabled="type === 2"
          style="width: 100%"
        />
      </template>
    </el-table-column>
    <el-table-column label="地点" type="index" width="250" align="center">
      <template #default="{ row }">
        <el-input v-model="row.place" placeholder="请输入地点" :disabled="type === 2" />
      </template>
    </el-table-column>
    <el-table-column label="主要责任人" type="index" width="150" align="center">
      <template #default="{ row }">
        <el-input v-model="row.mainPerson" placeholder="请输入主要责任人" :disabled="type === 2" />
      </template>
    </el-table-column>
    <el-table-column label="次要责任人" type="index" width="150" align="center">
      <template #default="{ row }">
        <el-input v-model="row.minorPerson" placeholder="请输入次要责任人" :disabled="type === 2" />
      </template>
    </el-table-column>
    <el-table-column label="事故原因" type="index" min-width="400" align="center">
      <template #default="{ row }">
        <el-input
          v-model="row.accidentReason"
          type="textarea"
          :rows="4"
          placeholder="请输入事故原因"
          :disabled="type === 2"
        />
      </template>
    </el-table-column>
    <el-table-column label="事故照片" type="index" width="150" align="center">
      <template #default="{ row, $index }">
        <upload-img
          :imgList="row.accidentImgs"
          @success="handleUpdateImg($event, $index)"
          :disabled="type === 2"
        ></upload-img>
      </template>
    </el-table-column>
    <el-table-column label="操作" align="center" fixed="right" width="120">
      <template #default="{ $index }">
        <el-button v-if="type !== 2" type="danger" @click="handleDeleRecord($index)"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup lang="ts">
const emits = defineEmits(["deleRecord", "updateImg"]);
defineProps({
  type: {
    type: Number,
    default: 0
  },
  tableData: {
    type: Array,
    default: () => []
  }
});
const handleUpdateImg = (e: any, index: number) => {
  emits("updateImg", e, index);
};
const handleDeleRecord = (index: number) => {
  emits("deleRecord", index);
};
</script>
<style scoped lang="scss"></style>
